package com.aaa.dao.impl;

import com.aaa.dao.PtypeDao;
import com.aaa.entity.Ptype;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
@Repository
public class PtypeDaoImpl implements PtypeDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    private RowMapper<Ptype> rowMapper=new RowMapper<Ptype>() {
        public Ptype mapRow(ResultSet resultSet, int i) throws SQLException {
            Ptype ptype=new Ptype();
            ptype.setTid(resultSet.getLong("tid"));
            ptype.setTname(resultSet.getString("tname"));
            return ptype;
        }
    };

    public List<Ptype> listAll() {
        String sql="select tid,tname from ptype";
        List<Ptype> result = this.jdbcTemplate.query(sql, rowMapper);
        return result;
    }
}
